Page({
  data: {
    name: '',
    phone: '',
    address: '',
    showAddress: false
  },
  onLoad() {
    wx.request({
      url: 'https://visa.goldenholiday.com/api/miniapp/admin/user/address',
      method: 'GET',
      success: (res) => {
        if (Array.isArray(res.data)) {
          const showAddr = res.data.find(item => item.status === 1)
          if (showAddr) {
            this.setData({
              name: showAddr.name,
              phone: showAddr.phone,
              address: showAddr.address,
              showAddress: true
            })
          } else {
            this.setData({ showAddress: false })
          }
        } else {
          this.setData({ showAddress: false })
        }
      }
    })
  },
  copyAddress() {
    const { name, phone, address } = this.data
    wx.setClipboardData({
      data: `${name} ${phone} ${address}`,
      success: function () {
        wx.showToast({
          title: '已复制',
          icon: 'success'
        })
      }
    })
  }
})